import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';

@Injectable()
export class Demo5Service {
  constructor(private http: HttpClient) {}

  getUsersBySort(sort: 'asc' | 'desc' | '' = 'asc') {
    return this.http
      .get('assets/mockdata/user.json', { params: { $prefix: 'none' } })
      .pipe(map((res: any[]) => (sort === 'asc' ? res : res.reverse())));
  }
}
